package com.example.myapplication.tools;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.myapplication.R;

//import vip.tianteng.mobile.healthsystemwh.R;

public class ToastUtils {
	
	public void showMessage(int resourceId, Context context) {
		LayoutInflater mLayoutInflater = LayoutInflater.from(context);
		View toastRoot = mLayoutInflater.inflate(R.layout.inflate_toast, null);
		TextView message = (TextView) toastRoot.findViewById(R.id.message);
		message.setTextSize(18);
		String str = context.getResources().getString(resourceId);
		message.setText(str);
		Toast toastStart = new Toast(context);
		showToast(toastStart,toastRoot);
	}

	public void showMessage(String msg, Context context) {
		LayoutInflater mLayoutInflater = LayoutInflater.from(context);
		View toastRoot = mLayoutInflater.inflate(R.layout.inflate_toast, null);
		TextView message = (TextView) toastRoot.findViewById(R.id.message);
		message.setTextSize(18);
		message.setText(msg);
		Toast toastStart = new Toast(context);
		showToast(toastStart,toastRoot);
	}
	
	public void showToast(Toast toastStart , View v){
		toastStart.setGravity(Gravity.BOTTOM, 0, 180);
		toastStart.setDuration(Toast.LENGTH_SHORT);
		toastStart.setView(v);
		toastStart.show();
	}
	
	public static void showMessages(int resourceId, Context context) {
		LayoutInflater mLayoutInflater = LayoutInflater.from(context);
		View toastRoot = mLayoutInflater.inflate(R.layout.inflate_toast, null);
		TextView message = (TextView) toastRoot.findViewById(R.id.message);
		message.setTextSize(18);
		String str = context.getResources().getString(resourceId);
		message.setText(str);
		Toast toastStart = new Toast(context);
		showToasts(toastStart,toastRoot);
	}

	public static void showMessages(String msg, Context context) {
		LayoutInflater mLayoutInflater = LayoutInflater.from(context);
		View toastRoot = mLayoutInflater.inflate(R.layout.inflate_toast, null);
		TextView message = (TextView) toastRoot.findViewById(R.id.message);
		message.setTextSize(18);
		message.setText(msg);
		Toast toastStart = new Toast(context);
		showToasts(toastStart,toastRoot);
	}
	
	public static void showMessages(int resourceId, Context context,boolean isSuccess) {
		LayoutInflater mLayoutInflater = LayoutInflater.from(context);
		View toastRoot = mLayoutInflater.inflate(R.layout.inflate_toast, null);
		TextView message = (TextView) toastRoot.findViewById(R.id.message);
		if(isSuccess){
			message.setTextColor(Color.GREEN);
		}else{
			message.setTextColor(Color.RED);
		}
		message.setTextSize(18);
		String str = context.getResources().getString(resourceId);
		message.setText(str);
		Toast toastStart = new Toast(context);
		showToasts(toastStart,toastRoot);
	}

	public static void showMessages(String msg, Context context,boolean isSuccess) {
		LayoutInflater mLayoutInflater = LayoutInflater.from(context);
		View toastRoot = mLayoutInflater.inflate(R.layout.inflate_toast, null);
		TextView message = (TextView) toastRoot.findViewById(R.id.message);
		if(isSuccess){
			message.setTextColor(Color.GREEN);
		}else{
			message.setTextColor(Color.RED);
		}
		message.setTextSize(18);
		message.setText(msg);
		Toast toastStart = new Toast(context);
		showToasts(toastStart,toastRoot);
	}
	
	public static void showToasts(Toast toastStart , View v){
		toastStart.setGravity(Gravity.BOTTOM, 0, 180);
		toastStart.setDuration(Toast.LENGTH_SHORT);
		toastStart.setView(v);
		toastStart.show();
	}
}
